//app.js
var c=require("/pages/common.js")
App({
  onLaunch: function () {
    // 展示本地存储能力
    var userInfo = wx.getStorageSync('userInfo') || []
    wx.showLoading({
      title: '加载中请稍后',
    })
    var that=this
    // 登录
    wx.login({
      success: res => {

        c.ajax(
          that.globalData.rootPath+"/index.php/index/Wxapi/getopenid",
          {
            code:res.code,
            appid:that.globalData.appid,
            appsecret:that.globalData.appsecret
          },
          r =>{
  
           var tem=JSON.parse(r.data)
           that.globalData.openid=tem.openid
           wx.setStorageSync("openid", tem.openid)
           that.globalData.session_key=tem.session_key
           if (tem.unionid == undefined&&userInfo.length==0){
            wx.redirectTo({
              url: '/pages/login/index',
            })
           }
           else{
             c.ajax(
               that.globalData.rootPath+"/index.php/index/Wxapi/checkunionid",
               {
                 unionid: tem.unionid
               },
               res=>{
                 if(res.data!=0){
                   that.globalData.unionid = tem.unionid
                   wx.setStorageSync("userInfo", res.data)
                   
                 }
               }
             )

           }
           setTimeout(()=>{
              wx.hideLoading()
           },500)

          }
        )
      }
    })
    },
  globalData: {
    userInfo: null,
    appid: 'wxeba1187209c57d5a',
    appsecret:'f46eb5f31ecce60ac6e68342b76a2efb',
    rootPath:"http://www.wk.com",//"https://xwz.wyuek.com",
    unionid:""
  },
  filePath: "http://wyk-img-1255995999.cos.ap-beijing.myqcloud.com",//"https://xwz.wyuek.com",
  url:"http://www.wk.com/index.php/index/Wxapi/",
  dbs: "http://www.wk.com/index.php/s/",
  imgurl: "http://wyk-img-1255995999.cos.ap-beijing.myqcloud.com",
  testimgurl:"https://sys-1252230039.cos.ap-chengdu.myqcloud.com",
  u:wx.getStorageSync('userInfo'),
  
})